package com.happyclub.paul;

import com.happyclub.paul.dao.AdviceShenheRepostirory;
import com.happyclub.paul.service.IUserAdviceService;
import com.happyclub.pojo.TbUser;
import com.happyclub.pojo.TbUserAdvice;
import com.happyclub.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: 魏泉琦
 * @Date: 2019/4/4 09:40
 * @Description: 意见反馈
 */
@Controller
public class UserAdviceController {

    @Autowired
    private IUserAdviceService userAdviceService;


    @RequestMapping(value = "showUserAdvice")
    public String showUserAdvice(){
        return "paul-html/showUserAdvice";
    }


    /**
     *@Description: 保存用户的意见反馈
     *@Author: 魏泉琦
     *@date: 2019/4/4
     */
    @ResponseBody
    @RequestMapping(value = "saveUserAdviceContent/{content}")
    public JsonResult saveUserAdviceContent(@PathVariable("content") String content, HttpServletRequest request){
      /*  HttpSession session = request.getSession();
        User user =(User) session.getAttribute("user");
        return  userAdviceService.saveUserAdviceContent(content,user.getUserId(),user.getTelephone());*/

        //测试
        return  userAdviceService.saveUserAdviceContent(content,"a75fb9d8963a4ae289d7d8f94e6818ee","1111111111111111");
    }

    /**
     *@Description: 查询所有的用户意见
     *@Author: 魏泉琦
     *@date: 2019/4/12
     */
    @ResponseBody
    @RequestMapping(value = "findALlUserAdvice")
    public JsonResult findALlUserAdvice(){
       return  userAdviceService.findALlUserAdvice(0);       //查询未被处理的用户意见
    }


    /**
     *@Description: 获取意见回复
     *@Author: 魏泉琦
     *@date: 2019/4/12
     */
    @ResponseBody
    @RequestMapping(value = "saveEditUserAdvice/{replyContent}_{userAdviceId}")
    public JsonResult saveEditUserAdvice(HttpServletRequest request,@RequestParam(value = "infoLovel") long infoLovel ,@RequestParam(value = "isUpperTracker") long isUpperTracker, @PathVariable("replyContent") String replyContent, @PathVariable("userAdviceId") String userAdviceId){
        TbUser user = (TbUser) request.getSession().getAttribute("user");
        //修改用户意见反馈的信息级别和是否需要后期跟踪
        return userAdviceService.updateUserAdvicesByAdviceId(user, replyContent, infoLovel, isUpperTracker,1, userAdviceId);
    }
}
